package ventanas;

import gestoresBD.GestorPartidas;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;

import clasesBasicas.Partida;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import logica.GestorFiguras;

public class venGuardarPartida extends JFrame implements ActionListener{

	private JPanel contentPane;
	private JTextField textField;
	private JButton btnAceptar;
	private JButton btnCancelar;
	

	private GestorPartidas gP;
	private Partida p;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					venGuardarPartida frame = new venGuardarPartida(null);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public venGuardarPartida(Partida p) {
		
		this.gP = new GestorPartidas();
		this.p = p;
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 337, 201);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblElijaUnNombre = new JLabel("Elija el nombre de la partida: ");
		lblElijaUnNombre.setFont(new Font("Segoe Script", Font.PLAIN, 15));
		lblElijaUnNombre.setBounds(42, 18, 254, 25);
		contentPane.add(lblElijaUnNombre);
		
		textField = new JTextField();
		textField.setBounds(52, 54, 174, 28);
		contentPane.add(textField);
		textField.setColumns(10);
		
		btnAceptar = new JButton("Aceptar");
		btnAceptar.setFont(new Font("Segoe Script", Font.PLAIN, 15));
		btnAceptar.setBounds(35, 123, 108, 29);
		contentPane.add(btnAceptar);
		
		btnCancelar = new JButton("Cancelar");
		btnCancelar.setFont(new Font("Segoe Script", Font.PLAIN, 15));
		btnCancelar.setBounds(193, 123, 117, 29);
		contentPane.add(btnCancelar);
		
		this.setLocationRelativeTo(null);
		btnAceptar.addActionListener(this);
		btnCancelar.addActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		JButton boton=(JButton)arg0.getSource();
		
		if(boton == btnAceptar){
			
			p.setNombre(textField.getText());
			//try {
				//gP.guardarPartida(p);
			//} catch (SQLException e) {
				// TODO Auto-generated catch block
			//	e.printStackTrace();
			//}
			this.setVisible(false);
			ventanaPrin vp = new ventanaPrin(null);
			vp.setVisible(true);
			JOptionPane.showMessageDialog(null,"Partida Guardada!!");
		}
		/*else if(boton == btnCancelar){
			this.setVisible(false);
			ventanaTablero2 vt2=new ventanaTablero2();
			vt2.setVisible(true);
		}	*/
		
		
	}
	
}
